<?php
namespace app\wxapp\controller;

use app\model\Theme; 
use app\model\Poster; 
use app\model\Worker; 

class Viewshop extends Base
{
    public function Viewshop()
    {

    global $_P, $_G;
    $system=$_G['system'];
    $fans = $this->checkuser();
    $themeid = intval($_P['themeid']);
    $id = intval($_P['id']);
    $theme = Theme::getThemeByIdxcx($themeid);
    if(empty($theme['id']) || empty($id)){
        wxapp_result(1, '活动入口不正确');
        exit;
    }

$config =   Theme::getConfig($themeid);


    db_query("UPDATE ".tablename(t_shangjia)." SET liulan = liulan +1 WHERE id = '{$id}'");
    $shangjia=db_find("SELECT * FROM ".tablename(t_shangjia)." WHERE id = '{$id}'");
    if (!empty($shangjia['topimgs'])){
        $topimgs=explode(';', $shangjia['topimgs']);
        $shangjia['topimgs'] = $topimgs;
    }
//    //读取商家信息和图片
//    $imgs = array();
//    if (!empty($shangjia['topimgs'])){
//        $topimgs=explode(';', $shangjia['topimgs']);
//        foreach ($topimgs as $index => $row) {
//            array_push($imgs, array('type' =>'img' ,'url' =>$row ));
//        }
//    }
//    if (!empty($shangjia['contentxcx'])) {
//        $content=Poster::getContentvideoimg($shangjia['content']);
//        array_push($imgs,$content);
//    }
//    $shangjia['content'] = $imgs;




    $shareinfo =Theme::getshareinfo($system,$theme,$config,$fans,$shopname,$workername,$recordid);
    $theme['jubf']=empty($theme['jubf'])?mb_substr($theme['title'],0,12,'utf-8'):$theme['jubf'];
    $themenew= array(
        'jubf'=>$theme['jubf'],
        'mobile'=> $theme['mobile'],
    );


    $result =  array();
    $result['jishu']=Worker::getjishu($theme,$system);
    $result['shangjia']=$shangjia;
    $result['shareinfo']=$shareinfo;
    $result['theme']=$themenew;
    wxapp_result(0, '成功', $result);
}
}